package edu.pku.sei.transformation.editor.parser.expression.element;

import edu.pku.sei.modeler.model.core.MetaModelElement;

public class IfExpression extends Expression {
	private Expression conditionExp;
	private Expression ifExpression;
	private Expression elseExpression;

	public String toString() {
		String s = new String();
		s += "if (" + conditionExp.toString() + ")";
		s += ifExpression.toString();
		if (elseExpression != null) {
			s += " else " + elseExpression.toString();
		}
		return s;

	}

	public Expression getConditionExp() {
		return conditionExp;
	}

	public void setConditionExp(Expression conditionExp) {
		this.conditionExp = conditionExp;
	}

	public Expression getElseExpression() {
		return elseExpression;
	}

	public void setElseExpression(Expression elseExpression) {
		this.elseExpression = elseExpression;
	}

	public Expression getIfExpression() {
		return ifExpression;
	}

	public void setIfExpression(Expression ifExpression) {
		this.ifExpression = ifExpression;
	}

	// public Element toXML(Element root) {
	// Element ele = root.addElement("ifExp");
	// this.conditionExp.toXML(ele.addElement("condition"));
	// this.ifExpression.toXML(ele.addElement("then"));
	// if(this.elseExpression != null)
	// this.elseExpression.toXML(ele.addElement("else"));
	// return ele;
	// }
	@Override
	public boolean bind(Object context) {

		return this.ifExpression.bind(context)
				&& this.conditionExp.bind(context)
				&& this.elseExpression.bind(context);
	}

	@Override
	public MetaModelElement getType() {
		return null;
	}

	@Override
	public void sendHighLightNotify() {
		this.ifExpression.sendHighLightNotify();
		this.conditionExp.sendHighLightNotify();
		this.elseExpression.sendHighLightNotify();
	}

	@Override
	public void removeInvalidBinding() {
		this.ifExpression.removeInvalidBinding();
		this.elseExpression.removeInvalidBinding();
		this.conditionExp.removeInvalidBinding();
	}
}
